import kdform from "./components/kdForm.vue";
import kdcrud from "./components/kdcrud.vue";
import kdlayout from "./components/kdlayout.vue";
import * as api from "@/utils/api"
// 导入forms文件夹下的所有组件
const formComponents = import.meta.globEager("./components/forms/*.vue");
// 导入layout文件夹下的所有组件
const layoutComponents = import.meta.globEager("./components/layout/*.vue");
const install = (Vue) => {
  Vue.component("kdform", kdform);
  Vue.component("kdcrud", kdcrud);
  Vue.component("kdlayout", kdlayout);
  // 合并到一起，通过遍历完成全局组件的创建
  Object.assign(formComponents, layoutComponents);
  Object.keys(formComponents).forEach((item) => {
    const comp = formComponents[item].default;
    const name = item.split("/")[3].split(".")[0];
    Vue.component(name, comp);
  });
  
  //全局挂在请求api
  for (let key in api){
    if (api[key]) Vue.config.globalProperties[key] = api[key];
  }
};
export default install;
